package com.px.controller;

import com.px.mapper.CollectionDao;
import com.px.mapper.CommentDao;
import com.px.mapper.CommodityDao;
import com.px.pojo.ShCollection;
import com.px.pojo.ShComment;
import com.px.pojo.ShCommodity;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class GoodsController {

    @Resource
    private CommodityDao commodityDao;
    @Resource
    private CommentDao commentDao;
    @Resource
    private CollectionDao collectionDao;
    //获取商品详情页面
    @PostMapping("/api/provider/goodsShow")
    public ShCommodity goodsShow(@RequestParam Integer commodityid)throws Exception{
        return commodityDao.queryById(commodityid);
    }
    //获取商品总行数
    @PostMapping("/api/provider/goodsCount")
    public Integer goodsCount(@RequestParam(required = false) String commodityName,
                              @RequestParam(required = false) Integer dicOneId,
                              @RequestParam(required = false) Integer dicTwoId)throws Exception{
        return commodityDao.count(commodityName,dicOneId,dicTwoId);

    }
    //获取商品信息
    @PostMapping("/api/provider/goodsList")
    public List<ShCommodity> goodsList(@RequestParam(required = false) String commodityName,
                                       @RequestParam(required = false) Integer dicOneId,
                                       @RequestParam(required = false) Integer dicTwoId,
                                       @RequestParam(defaultValue = "1") Integer pageBegin,
                                       @RequestParam(defaultValue = "2") Integer pageSize)throws Exception{
        return commodityDao.selectShCommodityList(commodityName,dicOneId,dicTwoId,pageBegin,pageSize);
    }

    //获取指定评论
    @PostMapping("/api/provider/commentShow")
    public ShComment commentShow(@RequestParam Integer commentId){
       return commentDao.queryById(commentId);
    }

    //根据购物车id查询商品id
    //查询购物车详细信息
    @PostMapping("/api/provider/collectionShow")
    public ShCollection collectionShow(@RequestParam Integer collectionId)throws Exception{
        return collectionDao.queryById(collectionId);
    }
    //根据商品id查询商品详情
    @PostMapping("/api/provider/goodsDityShow")
    public ShCommodity goodsDityShow(@RequestParam Integer commodityId)throws Exception{
        return collectionDao.queryDityById(commodityId);
    }
    //获取最新商品
    @PostMapping("/api/provider/newGoodsList")
    public List<ShCommodity> newGoodsList()throws Exception{
        return commodityDao.newGoodsList();
    }
    @PostMapping("/api/provider/searchGoodsList")
    public List<ShCommodity> searchGoodsList(@RequestParam(required = false) String commodityName,
                                             @RequestParam(required = false) Integer dicOneId,
                                             @RequestParam(required = false) Integer dicTwoId)throws Exception{
        return commodityDao.searchGoodsList(commodityName,dicOneId,dicTwoId);
    }


    //根据商品ID查询商品信息
    @PostMapping("/api/provider/commodity/selectGoodsById")
    public ShCommodity selectGoodsById(@RequestParam Integer id) throws Exception{
        return commodityDao.selectCommodityById(id);
    }

}
